<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>大于10</title>
  </head>
  <body>
    <script>
      var arr = [1, 1, 1, 15, 6, 7, 7, 34, 2, 43, 2, 66, 3, 3];
      var newArr = [];
      // 方法一 for
      // for (var i = 0; i <= arr.length - 1; i++) {
      //   if (arr[i] > 10) {
      //     newArr.push(arr[i]);
      //   }
      // }

      // 方法二 forEach
      // arr.forEach((item, index) => {
      //   if (item > 10) {
      //     newArr.push(item);
      //   }
      // });

      // 方法三 filter
      var newArr = arr.filter((item, index) => item > 10);

      // 方法四 reduce(有瑕疵！！！！！获得字符串)
      var newArr = arr
        .reduce((result, current) => {
          return (
            result +
            (result && current > 10 ? "," : "") +
            (current > 10 ? current : "")
          );
        }, "")
        .split(",");

      console.log(newArr);
    </script>
  </body>
</html>
